-
Notifications
You must be signed in to change notification settings - Fork 45
fix: safely getting all the values for trigger tags #593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -114,10 +114,14 @@ def parse_event_source(event: dict) -> _EventSource: | |||
|
|||
event_source = None | |||
|
|||
request_context = event.get("requestContext") | |||
# Get requestContext safely and ensure it's a dictionary | |||
request_context = event.get("requestContext", {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's better to do request_context = event.get("requestContext") or {}
becuase it will avoid an allocation in the case that the key is found in the dict.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's some expert level advice on allocation, thanks!
# Get requestContext safely and ensure it's a dictionary | ||
request_context = event.get("requestContext", {}) | ||
if not isinstance(request_context, dict): | ||
request_context = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would probably be better in this case to set request_context = None
. This way we avoid the extra allocation and we don't even attempt any of the request_context.get
s that happen after.
# Safely get request_context and ensure it's a dictionary | ||
request_context = event.get("requestContext", {}) | ||
if not isinstance(request_context, dict): | ||
request_context = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. I think we can do this more efficiently.
What does this PR do?
Make sure we get the
trigger_tags
values safely without raising exceptions. We have some customer's payload that cannot be properly handled currently.As an alternative, there's a
try-catch-call
solution. (Not recommended)The recommended approach is this PR.
Motivation
https://datadoghq.atlassian.net/browse/APMSVLS-10
Customer ticket:
https://datadoghq.atlassian.net/browse/SLES-2218
Testing Guidelines
Additional Notes
Types of Changes
Check all that apply